<?php

namespace frontend\helpers;
use yii\helpers\Url;
use yii\helpers\Inflector;

class EventRenderHelper
{
    public static function eventMenu($data)
    {
        foreach($data as $eventType)
        {
            if(count($eventType['events']) != null)
            {
                echo '<a href="#' . Inflector::slug($eventType['title_plural']) . '" class="base-button">' . $eventType['title_plural'] . '</a>';
            }
        }
    }

    public static function sectorTitle($title)
    {
        echo '<h1 class="event-sector-title" id="' . Inflector::slug($title) . '">' . $title . '</h1>';
    }

    public static function eventItem($data, $sectorTitle)
    {   
        if($data['prev_img']) 
        { 
            $cover = 'https://storage.yandexcloud.net/' . \backend\models\Event::BUCKET_NAME . '/' . $data['prev_img'];
        }
        else 
        {
            $cover = \backend\models\Event::DEFAULT_COVER;
        }

        echo '<div class="event-item clearfix">
                <div class="col-md-4 event-item__img">
                    <img src="' . $cover . '">
                </div>
                <div class="col-md-4 event-item__content">
                    <p class="event-item__type">' . $sectorTitle . '</p>
                    <h2 class="event-item__title">' . $data['title'] . '</h2>
                    <p class="event-item__description">' . $data['description'] . '</p>
                    <a class="event-item__more-link" href="' .  Url::to(['event/view', 'id' => $data['id']]) . '">подробнее</a>
                </div>
                <div class="col-md-4 event-item__subinfo">
                    <p>
                        расписание<br>
                        ' . $data['schedule_str'] . '
                    </p>
                    <p>' . self::pushkartString($data['is_pushkart']) . '</p>
                    <p>' . $data['rars_info'] . '</p>'
                    . self::buyKassirButton($data['kassir_bo_type'], $data['kassir_bo_id'], $data['is_free']) .
                '</div>
            </div>';
    }

    public static function mainEvent($data)
    {
        echo '<div class="event-main-item clearfix">
                <div class="col-md-4 event-main-item__title">
                    <h2>' . $data['title'] . '</h2>
                </div>
                <div class="col-md-8 event-main-item__content">
                    ' . $data['content'] . '
                </div>
            </div>';
    }

    public static function buyKassirButton($type, $id, $isFree)
    {
        if(!$isFree)
        {
            $href = 'https://orenburg.kassir.ru/frame/entry/index?key=2b1d464c-9a91-c371-d762-4f2f19a234bc&type=' . $type . '&id=' . $id;
            return '<a class="base-button base-button--black" href="' . $href . '" onclick="return window.kassirWidget.summon({width:960,url:\'' . $href . '\'})">купить билет</a>';
        }
        else 
        {
            return '<p>вход свободный</p>';
        }
        
    }

    public static function pushkartString($isPushkart)
    {
        if($isPushkart)
        {
            return 'доступно<br>по пушкинской карте';
        }
    }
}